<template>
	<view class="">
		<view class="coupon-container">
			<view class="coupon-item" v-for="(item,index) in couponList" :key="index">
				<view class="coupon-left">
					<view class="coupon-money">￥{{item.discount}}</view>
					<view class="coupon-time">
						使用时间：{{item.startTime}} 至 {{item.endTime}}
					</view>
				</view>
				<view @click="goDetail(item)" class="coupon-right">
					查看详情
				</view>
			</view>
		</view>
		<view v-if="checkDetailVisible == true">
			<u-popup :show="show" :round="5" mode="center" @close="close" closeable>
				<view class="coupon">
					<view style="margin: 0 auto 20rpx;">
						优惠券编号
					</view>
					<view style="display: flex;">
						<view class="coupon-uuid">
							{{value}}
						</view>
						<!-- 					  <u-input
					    border="round"
					    v-model="value"
						type="text"
						disabled
					  ></u-input> -->
						<u-button :plain="true" text="复制" style="width: 80rpx;margin-left:20rpx" @click="copy">
						</u-button>
					</view>
				</view>
			</u-popup>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				checkDetailVisible: false,
				show: false,
				value: 111,
				couponList: []
			}
		},
		onLoad() {
			this.getCouponList()
		},
		methods: {
			getCouponList() {
				this.$api.request('coupon', 'getUserCoupons').then(res => {
					this.couponList = res.data
					console.log(this.couponList, 777);
				})
			},
			goDetail(item) {
				console.log(item);
				this.checkDetailVisible = true
				this.show = !this.show
				this.value = item.uuid
				console.log(this.value);
			},
			close() {
				this.show = false
			},
			copy() {
				uni.setClipboardData({
					data: this.value,
					success: () => {
						uni.showToast({
							title: '复制成功'
						})
					}
				})
			}
		}
	}
</script>

<style lang='scss'>
	.coupon-container {
		padding: 20upx 20upx;
	}

	.coupon-item {
		width: 100%;
		height: auto;
		display: table;
		border-radius: 10upx;
		padding: 0 20upx;
		margin-top: 20upx;
		border: 1px solid #eeeeee;
		position: relative;

		.coupon-left {
			width: 465upx;
			height: auto;
			display: table;
			float: left;
			padding: 26upx 0;
			border-style: none dotted none none;
			border-color: #eeeeee;

			.coupon-money {
				width: 100%;
				height: 55upx;
				line-height: 55upx;
				font-size: 50upx;
				color: red;
				font-weight: bold;
				margin-bottom: 10upx;
			}

			.coupon-time {
				width: 100%;
				height: 30upx;
				line-height: 30upx;
				font-size: $font-sm;
				color: #999999;
			}
		}

		.coupon-right {
			width: 146upx;
			height: 52upx;
			line-height: 50upx;
			position: absolute;
			top: 50%;
			right: 32upx;
			margin-top: -26upx;
			text-align: center;
			border-radius: 60upx;
			color: #ff9000;
			border: 1px solid #ff9000;
			font-size: $font-sm;
			float: right;
		}
	}

	.coupon-item:after {
		width: 40upx;
		height: 20upx;
		position: absolute;
		left: 460upx;
		top: -1px;
		border-radius: 0 0 40upx 40upx;
		content: "";
		display: block;
		background: #FFF;
		border: 1px solid #eeeeee;
		border-top: 0px;
	}

	.coupon-item:before {
		width: 40upx;
		height: 20upx;
		position: absolute;
		left: 460upx;
		bottom: -1px;
		border-radius: 40upx 40upx 0 0;
		content: "";
		display: block;
		background: #FFF;
		border: 1px solid #eeeeee;
		border-bottom: 0px;
	}

	.coupon {
		display: flex;
		flex-direction: column;
		background: #FFFFFF;
		flex: 1;
		padding: 20rpx 40rpx;
		margin: 20rpx;
	}
	.coupon-uuid{
		border-radius: 15rpx;
		background-color: #d3d3d3;
		line-height: 40px;
		margin-right: 10px;
		padding: 0 10px;
	}
</style>
